package cn.tedu.csms.order.service.impl;

import cn.tedu.csms.employee.pojo.vo.EmployeeVO;
import cn.tedu.csms.order.mapper.OrderMapper;
import cn.tedu.csms.order.pojo.dto.OrderQuery;
import cn.tedu.csms.order.pojo.dto.OrderSaveParam;
import cn.tedu.csms.order.pojo.entity.Order;
import cn.tedu.csms.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class OrderServiceImpl implements IOrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public List<EmployeeVO> select(OrderQuery orderQuery) {
        log.debug("查询订单业务:参数={}",orderQuery);
        return orderMapper.select(orderQuery);

    }

    @Override
    public void save(OrderSaveParam orderSaveParam) {
        log.debug("保存订单业务:参数={}",orderSaveParam);
        Order order = new Order();
        BeanUtils.copyProperties(orderSaveParam,order);
        if(order.getId()==null){
            order.setOrderTime(new Date());
            orderMapper.insert(order);
        }else{
            order.setUpdateTime(new Date());
            orderMapper.update(order);
        }

    }

    @Override
    public void delete(Long id) {
        log.debug("删除订单业务:参数={}",id);
        orderMapper.delete(id);
    }

}
